package com.android.publicModule.webview;

import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;

public class MugeWebView extends WebView {
	
	private OnScrollChangedListener onScrollChangedListener;
    public MugeWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public MugeWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MugeWebView(Context context) {
        super(context);
    }
    
    public int getVerticalScrollLeftDistance() {
    	return this.computeVerticalScrollRange()-getHeight()-getScrollY();//(int)(getContentHeight()*getScale())-(getHeight()+getScrollY());
    }
    
    public int getHorizontalScrollLeftDistance() {
    	return this.computeHorizontalScrollRange()-getWidth()-getScrollX();
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if(onScrollChangedListener!=null)
        {
        	if(t<=0)
        	{
        		onScrollChangedListener.onScrollTop(l, t, oldl, oldt);
        	}
        	else if(getVerticalScrollLeftDistance()<=0)
        	{
        		onScrollChangedListener.onScrollBottom(l, t, oldl, oldt);
        	}
        	if(l<=0)
        	{
        		onScrollChangedListener.onScrollLeft(l, t, oldl, oldt);
        	}
        	else if(getHorizontalScrollLeftDistance()<=0) {
        		onScrollChangedListener.onScrollRight(l, t, oldl, oldt);
        	}
        	onScrollChangedListener.onScrollChanged(l, t, oldl, oldt);
        }
    }
    
    /**
     * 绑定
     * @param listener
     */
    public void setOnScrollChangeListener(OnScrollChangedListener listener){
    	onScrollChangedListener = listener;
    }
    
}
